package com.study.sort;

import java.util.Arrays;

public abstract class Sort {

    public int[] run(int[] list) {
        long start = System.nanoTime();
        sort(list);
        long end = System.nanoTime();
//        System.out.println(Arrays.toString(list));
        long time = end - start;
        boolean result = check(list);
        System.out.println(sortName() + " time: " + time + ", result: " + result);
        return list;
    }

    private boolean check(int[] list) {
        for (int i = 0; i < list.length - 1; i++) {
            if (list[i] > list[i + 1]) {
                return false;
            }
        }
        return true;
    }

    protected abstract String sortName();

    protected abstract void sort(int[] list);


    protected void swap(int[] list, int j, int i) {
        int temp = list[i];
        list[i] = list[j];
        list[j] = temp;
    }
}
